<?php namespace Summer\Hub\FormWidgets;

use Flash;
use Config;
use Backend\Classes\FormWidgetBase;

class Powerange extends FormWidgetBase
{
    protected $defaultAlias = 'powerange';
    /**
     * 是否有小数点
     */
    public $decimal = false;
    /**
     * 是否禁用
     */
    public $disabled = false;
    /**
     * 透明度
     */
    public $disableOpacity=1;
    /**
     * 是否隐藏最大最小值
     */
    public $hideRange = false;
    /**
     * 最小值
     */
    public $min;
    /**
     * 最大值
     */
    public $max;
    /**
     * 开始值
     */
    public $start;
    /**
     * 步长
     */
    public $step;
    /**
     * 是否竖的
     */
    public $vertical = false;
    /**
     * @inheritDoc
     */
    public function init()
    {
        $this->fillFromConfig([
            'decimal',
            'disable',
            'disableOpacity',
            'hideRange',
            'min',
            'max',
            'start',
            'step',
            'vertical'
        ]);
    }
    public function render() {
        $this->prepareVars();
        return $this->makePartial('powerange');
    }
    /**
     * Prepares the list data
     */
    public function prepareVars()
    {
        $this->vars['name'] = $this->getFieldName();
        $this->vars['value'] = $this->getLoadValue();
        $this->vars['decimal'] = (bool) $this->decimal;
        $this->vars['disable'] = (bool) $this->disable;
        $this->vars['disableOpacity'] = $this->disableOpacity;
        $this->vars['hideRange'] = (bool)$this->hideRange;
        $this->vars['min'] = $this->min;
        $this->vars['max'] = $this->max;
        $this->vars['start'] = $this->start??$this->getLoadValue();
        $this->vars['step'] = $this->step;
        $this->vars['vertical'] = (bool) $this->vertical;
    }
    /**
     * @inheritDoc
     */
    protected function loadAssets()
    {
        $this->addCss('powerange.css', 'core');
        $this->addJs('powerange.js', 'core');
    }
}
